package a66weding.com.jiehuntong.activity.me;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.HashMap;
import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.application.DataWareHourse;
import a66weding.com.jiehuntong.application.GlobalApplication;
import a66weding.com.jiehuntong.beans.CommonResultBean;
import a66weding.com.jiehuntong.beans.ErrorBean;
import a66weding.com.jiehuntong.beans.HttpRequestBean;
import a66weding.com.jiehuntong.beans.SuccessBean;
import a66weding.com.jiehuntong.common.utils.CUtils;
import a66weding.com.jiehuntong.common.utils.CacheUtils;
import a66weding.com.jiehuntong.http.HttpHandleUtil;
import a66weding.com.jiehuntong.http.OnNetResultListener;
import a66weding.com.jiehuntong.http.RequestCode;
import a66weding.com.jiehuntong.http.UrlDealUtil;
/**
 * 个人简介界面
 * Created by Administrator on 2016/7/5.
 */
public class MeUserResumeActivity extends MeBaseActivity implements View.OnClickListener, OnNetResultListener {
    private LinearLayout mBackLay;
    private TextView mBackContentTv;
    private TextView mHeaderTitleTv;
    private RelativeLayout mHeaderRightRlay;
    private EditText mResumeEt;
    private Button mAccomplishBt;
    private String personalIntroduction;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_me_user_resume);
        ((GlobalApplication)getApplication()).getActivityManager().addActivity("MeYetBindPhoneActivity",this);
        initview();
        initData();
    }
    private void initview() {
        mBackLay = (LinearLayout) findViewById(R.id.llay_header_back);
        mBackContentTv = (TextView) findViewById(R.id.tv_header_backcontent);
        mHeaderTitleTv = (TextView) findViewById(R.id.tv_header_title);
        mHeaderRightRlay = (RelativeLayout) findViewById(R.id.rlay_header_rightfunc);
        mResumeEt = (EditText) findViewById(R.id.et_me_set_content);
        mAccomplishBt = (Button) findViewById(R.id.btn_editcommit);
        mBackContentTv.setText("返回");
        mHeaderTitleTv.setText("个人简介");
        mHeaderRightRlay.setVisibility(View.GONE);
        mBackLay.setOnClickListener(this);
        mAccomplishBt.setOnClickListener(this);
    }
    private void initData(){
        if(DataWareHourse.getInstance().getmUser().getData().get(0).getNvc_PersonalIntroduction() != null &&
                !(DataWareHourse.getInstance().getmUser().getData().get(0).getNvc_PersonalIntroduction().equals(""))) {  //如果登录的简历内容不为空串
            mResumeEt.setText(DataWareHourse.getInstance().getmUser().getData().get(0).getNvc_PersonalIntroduction()); //只要一显示界面就去获取简历
        }
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.llay_header_back: // 点击返回,关闭界面
                finish();
                break;
            case R.id.btn_editcommit:   // 点击完成,做网络请求到服务器
                personalIntroduction = mResumeEt.getText().toString().trim();
                if(TextUtils.isEmpty(personalIntroduction)) {
                    CUtils.showToast("内容不能为空");
                    return;
                }
                // 发起网络请求,将简历内容提交到服务器
                String url= UrlDealUtil.getRealUrl(RequestCode.UPDATE_CUSTOMER);
                HashMap<String,String> requestParams=new HashMap<String,String>();
                requestParams.put("PersonalIntroduction",""+personalIntroduction);
                HttpRequestBean httpRequestBean = new HttpRequestBean(RequestCode.POSTEQUEST, url,
                        this, CommonResultBean.class, RequestCode.UPDATE_CUSTOMER, requestParams);
                HttpHandleUtil.executeCommonPost(this,httpRequestBean);
                break;
        }
    }

    @Override
    public void onSucess(SuccessBean sucessbean) {
        CUtils.showToast("简历提交成功");
        //更新内存
        DataWareHourse.getInstance().getmUser().getData().get(0).setNvc_PersonalIntroduction(personalIntroduction);
        //更新本地缓存
        CacheUtils.saveObjectToTextFile(RequestCode.TOLOGIN_ACTIVITY_REQUESTCODE, DataWareHourse.getInstance().getmUser());
        finish();
    }

    @Override
    public void onError(ErrorBean errorBean) {
        CUtils.showToast("服务器连接失败,请稍后再试");
    }
}
